package com.yumingjiang.weichatgtp.config;

import com.yumingjiang.weichatgtp.intercepter.ChatGPTParamsAndLogIntercepter;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ServiceInterceptorConfig {
    public static final String traceExecution = "execution(* com.yumingjiang.weichatgtp.service.impl.ChatGPTServiceImpl.chat(..))";

    @Bean
    public DefaultPointcutAdvisor defaultPointcutAdvisor(){
        ChatGPTParamsAndLogIntercepter methodInterceptor = new ChatGPTParamsAndLogIntercepter();
        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        pointcut.setExpression(traceExecution);

        DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
        advisor.setPointcut(pointcut);
        advisor.setAdvice(methodInterceptor);
        return advisor;
    }
}